<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>

	<body>
		<script>
			// TODO: 3. load 页面崩溃 利用网页关闭或刷新触发beforeunload事件，可以在利用service work上传信息
			window.addEventListener('load', function () {
				sessionStorage.setItem('good_exit', 'pending');
				setInterval(function () {
					sessionStorage.setItem('time_before_crash', new Date().toString());
				}, 1000);
			});

			window.addEventListener('beforeunload', function () {
				sessionStorage.setItem('good_exit', 'true');
			});

			if (sessionStorage.getItem('good_exit') && sessionStorage.getItem('good_exit') !== 'true') {
				/*
                insert crash logging code here
            */
				alert('Hey, welcome back from your crash, looks like you crashed on: ' + sessionStorage.getItem('time_before_crash'));
			}
		</script>
	</body>
</html>
